package com.driving.single.common.partner.service.impl;

import com.driving.single.common.domain.TbPartner;
import com.driving.single.common.entity.PageResult;
import com.driving.single.common.mapper.CustomFindItemsMapper;
import com.driving.single.common.mapper.TbPartnerMapper;
import com.driving.single.common.partner.service.CommonPartnerService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommonPartnerServiceImpl implements CommonPartnerService {
    @Autowired
    private TbPartnerMapper tbPartnerMapper;
    @Autowired
    private CustomFindItemsMapper customFindItemsMapper;
    /**
     * 根据主键查询陪练信息
     * @param id 陪练主键
     */
    @Override
    public TbPartner selectTbPartnerById(Long id) {
        return this.tbPartnerMapper.selectByPrimaryKey(id);
    }

    /**
     * 找陪练页面 - 分页+条件 查询陪练列表
     * @param page        当前页
     * @param rows        页显示数
     * @param area        查询条件：区域(学校名称)
     * @param licenseType 查询条件：驾照类型
     * @param minPrice    查询条件：最小价格
     * @param maxPrice    查询条件：最大价格
     */
    @Override
    public PageResult selectPartnerListByConditionWithPage(Integer page, Integer rows, String area,
                                                           String licenseType, Integer minPrice, Integer maxPrice) {
        PageHelper.startPage(page, rows);

        List<TbPartner> list = this.customFindItemsMapper.selectPartnerListByConditionWithPage(area,licenseType,
                minPrice, maxPrice);

        PageInfo<TbPartner> pageInfo = new PageInfo<>(list);

        PageResult pageResult = new PageResult();
        pageResult.setResult(list);
        pageResult.setPageIndex(page);
        pageResult.setTotalPage(pageInfo.getPages());
        pageResult.setTotalSize(pageInfo.getTotal());

        return pageResult;
    }
}
